/**
 * 新增-课题js
 */
var vm = new Vue({
	el:'#dpLTE',
	data: {
		srbliveClassroom: {
			  id: null,
            moneytype:0,/* 课题费用类型，0为免费，1为付费，2为加密 */
            // active:1,
            status:1,//课程状态: 1为正常,0为课程结束
            hascomment:1,
            hastip:1,
            type:0,
            livetype:null,
            liveparenttype:null,
            price:null,
            imageurl:"",
            content:null
		},
        liveparenttypes:[],
        livetypes:[],
        config:{},
        ue:UE.getEditor('srbliveClassroom-content')
	},
    watch: {
        "srbliveClassroom.liveparenttype": function (val, oldval) {
            if (val !== oldval) {
                var _vm = this;
                if(_vm){
                    Utils.getLiveRoomTypes({
                        pid: val,
                        serviceType:'getSon',
                        success: function (result) {
                            _vm.livetypes = result.rows;
                        }
                    });
                }
            }
        },
        "srbliveClassroom.moneytype":function (val, oldval) {
            if (val !== oldval) {
                //切换到加密时，清楚价格信息
                if(val!=1) vm.srbliveClassroom.price = null;
            }
        }
    },
	methods : {
		acceptClick: function() {
            //富文本-取值
            vm.srbliveClassroom.content = htmlEncodeByRegExp(vm.ue.getContent());

			if (!$('#form').Validform()) {
		        return false;
		    }
		    $.SaveForm({
		    	url: '../../srblive/classroom/save?_' + $.now(),
		    	param: vm.srbliveClassroom,
		    	success: function(data) {
		    		$.currentIframe().vm.load();
		    	}
		    });
		},
        getConfig: function () {
            $.getJSON("../../sys/oss/config", function(r){
                vm.config = r.config;
            });
        },
	},
    created: function(){
        this.getConfig();
    },
    beforeCreate:function () {
        //初始化父类型
        Utils.getLiveRoomTypes({
            success:function (result) {
                vm.liveparenttypes = result.rows;
            }
        });
    },
    mounted:function () {
        DateUtils.datetimepicker($('#srbliveClassroom-begintime'),
            { vmTarget: 'srbliveClassroom', property: 'begintime'},
            {
                startDate:new Date().Format("yyyy-MM-dd hh:mm:ss")
            });

        // setTimeout(function() {
        //     /******************图片上传开始***************************/
        //     var $list0 = $('#photoList');// $list为容器jQuery实例
        //     //每个图片有一个class=bannerImgurl的隐藏值
        //     window.uploader.init('imageurl',$list0,1,{token:token},vm.srbliveClassroom);
        //     /******************图片上传结束***************************/
        // },500);
        var vm = this;
        AjaxUploadUtils.cloudInit({
            targetId:'imageurl',
            success:function(file, r){
                vm.srbliveClassroom.imageurl = r.url;
            },
            extension:/^(jpg|jpeg|png|gif)$/,
            extensionMsg:'只支持jpg、png、gif格式的图片！',
        });
    }
})
